package de.koller.worlders.engine.entity.zone;

import de.koller.worlders.engine.tiles.ITile;
import de.koller.worlders.engine.tiles.data.ITileCreator;
import de.koller.worlders.engine.tiles.light.LightSource;
import de.koller.worlders.render.VisualMap;
import de.koller.worlders.render.visual.DisplayRenderObject;

public class SkyZone extends ZoneEffect {
	public static final int GEN_ID = 9;
	
	public static final ITileCreator GEN_INSTANCE = new ITileCreator() {
		@Override public ITile newInstance() {
			return new Zone().addEffect( new SkyZone( ZoneType.Sky ) );
		}
		
		@Override public DisplayRenderObject getIcon() { return VisualMap.sky; }
		@Override public String getName() { return "Himmel"; }
	};
	
	public static final ITileCreator GEN_INSTANCE_1 = new ITileCreator() {
		@Override public ITile newInstance() {
			return new Zone().addEffect( new SkyZone( ZoneType.Purple ) );
		}
		
		@Override public DisplayRenderObject getIcon() { return VisualMap.skyPurple; }
		@Override public String getName() { return "Lila Hintergrund"; }
	};
	
	public static final ITileCreator GEN_INSTANCE_2 = new ITileCreator() {
		@Override public ITile newInstance() {
			return new Zone().addEffect( new SkyZone( ZoneType.White ) );
		}
		
		@Override public DisplayRenderObject getIcon() { return VisualMap.skyWhite; }
		@Override public String getName() { return "Weißer Hintergrund"; }
	};
	
	public static final ITileCreator GEN_INSTANCE_3 = new ITileCreator() {
		@Override public ITile newInstance() {
			return new Zone().addEffect( new SkyZone( null ) );
		}
		
		@Override public DisplayRenderObject getIcon() { return VisualMap.invisible; }
		@Override public String getName() { return "Durchsichtig"; }
	};
	
	private final ZoneType disp;
	private LightSource lightSource;
	
	public SkyZone( ZoneType disp ) {
		this.disp = disp;
	}
	
	@Override
	public void init( Zone z ) {
		super.init( z );
	
//		if( disp == ZoneType.Sky )		z.setTextureRep( new TextureRep( "data/tiles.png", 352, 0, 32, 32 ) );
//		if( disp == ZoneType.Purple )	z.setTextureRep( new TextureRep( "data/tiles.png", 96, 32, 32, 32 ) );
//		if( disp == ZoneType.White )	z.setTextureRep( new TextureRep( "data/tiles.png", 288, 32, 32, 32 ) );
		
		if( disp == ZoneType.Sky )		z.getTile().setVisual( VisualMap.sky );
		if( disp == ZoneType.Purple )	z.getTile().setVisual( VisualMap.skyPurple );
		if( disp == ZoneType.White )	z.getTile().setVisual( VisualMap.skyWhite );
		if( disp == null )				z.getTile().setVisual( VisualMap.invisible );
		
		if( z.root == null )
			return;
		
//		if( disp == ZoneType.Sky )
//			lightSource = z.wroot.getTileMap().getLight().addLightSource( 
//					z.getTile().getPosition().getXi(), z.getTile().getPosition().getYi(), 0xffffffff );
	}

	@Override
	public void release() {
		super.release();
		
//		if( lightSource != null )
//			zone.wroot.getTileMap().getLight().removeLightSource( lightSource );
	}
	
	
	private static enum ZoneType {
		Sky, Purple, White;
	}
	
}
